/** 
Company    : Strand 
Date       : December 2013 
Author     :  
Description: Policyholder VF Controller
History    :               
**/
public with sharing class PolicyHolderEXT 
{
	    private List<Payment_Method__c> pmt;
        private List<Payment__c> paymt;  
        private List<Account> agent;  
        private List<Finance_Agreement__c> finAgr;  
            
        private Account account;   
        
        public User getUser()
        {
        	string uid = Userinfo.getUserId();
        	user userID = [select id from User Where Id =: uid];
        	
        	return userID;
        }  
        
        public PolicyHolderEXT(ApexPages.StandardController controller) 
        {        

                string userID = Userinfo.getUserId();
                Account act = new Account();
                
                User usr = [Select Id, ContactID from User Where Id =: userId]; 
                
                system.debug('contactid is: ' + usr.ContactId);
                
                if(usr != null)
                {
                	Contact con = [Select Id, AccountId From Contact Where Id =:usr.ContactId]; 
                	system.debug('Accountid is: ' + con.AccountId);
                
	                if(con != null)
	                {
	                	act = [Select Id From Account Where Id =: con.AccountId];
	                	system.debug('AccountId is: ' + con.AccountId);     
	                }
                }
                /*else
                {
                	act = [Select Id From Account Where Id = '001i000000IW88I'];
                }*/
                
                //this.account= (Account)controller.getRecord();   
                controller.
                
                account = new account(id=account.Id);  
                this.Account = account;
                system.debug('This is the account: ' + account);
                pageReference pr = new pagereference('/agent/apex/policyholder?id=' + act.id);
                return pr;
                            
               //this.Account= (Account)controller.getRecord();
        }    
        
        public List<Payment_Method__c>  getpmt()
        {           
                pmt = [Select Auto_Pay__c, Name, Account__r.Name,  First_Name__c, Last_Name__c, Primary_Method__c, Type__c 
                                from Payment_Method__c where Account__c = :account.Id];        
                return pmt;    
        }
        
        public List<Payment__c> getpaymt()    
        {        
                paymt = [Select PaymentDate__c, Name, Installment__c, Account__r.Name,  Principal_OLD__c, Interest__c, 
                			Late_Fee__c, Finance_Agreement__r.Name
                            from Payment__c where Account__c = :account.Id];        
                return paymt;    
        }
        
        public List<Account> getAgent()
        {        
                agent = [Select //firstName, lastName, Phone, email__c,
                			Name, Phone, email__c, 
	                		billingStreet, billingCity, billingState, billingPostalCode
	                		from Account where Id = :account.Agency__c];          
                return agent;    
        } 

        public List<Finance_Agreement__c> getFinAgr()
        {        
                finAgr = [SELECT Name, Balance_Due__c, Principal_Due__c, Monthly_Amount_Due__c,  
                		Current_Amount_Due__c, Current_Late_Fee__c, Late_Fee__c, Total_Payments__c, 
                		Remaining_Payments__c, Status__c 
                		FROM Finance_Agreement__c where Account__c = :account.Id];          
                return finAgr;    
        }
}